package com.qidian.mes.produce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.mes.pojo.Process;
import com.qidian.mes.produce.mapper.ProcessMapper;
import com.qidian.mes.produce.service.ProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/16 17:09
 */
@Service
public class ProcessServiceImpl implements ProcessService {
   @Autowired
    ProcessMapper processMapper;
    @Override
    public MESResult queryAll(Process process, int page, int limit) {
        PageHelper.startPage(page,limit);
        List<Process> processes = processMapper.queryAll(process);

        PageInfo<Process> projectPageInfo = new PageInfo<>(processes);
        return MESResult.success(projectPageInfo);

    }

    @Override
    public MESResult addProcess(Process process) {

            return MESResult.success(200,"OK",processMapper.addProcess(process));


    }

    @Override
    public MESResult modify(Process process) {
        if (processMapper.updateProcess(process)==1){
            return MESResult.success();
        }else {
            return MESResult.error();
        }

    }

    @Override
    public MESResult queryById(int processRelId) {
        return MESResult.success(processMapper.queryByRelId(processRelId));
    }

    @Override
    public MESResult delete(int processRelId) {
        if (processMapper.deleteProcess(processRelId)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult deleteAll(Process[] processes) {
        for (int i = 0; i < processes.length; i++) {
            if (processMapper.deleteProcess(processes[i].getProcessRelId())!=1){
                return MESResult.error();
            }

        }
        return MESResult.success();
    }

    @Override
    public MESResult queryProcessName() {
        Process process = new Process();
        return MESResult.success(processMapper.queryAll(process));
    }


}
